<?php

/**
 * This is the model class for table "tbl_admin".
 *
 * The followings are the available columns in table 'tbl_admin':
 * @property string $id
 * @property string $ho_va_ten
 * @property string $so_dien_thoai
 * @property string $email
 * @property integer $status
 * @property string $ngay_sinh
 * @property string $ngay_tao
 * @property string $ngay_chinh_sua
 * @property string $id_nguoi_tao
 * @property string $id_nguoi_chinh_sua
 * @property string $role
 * @property string $tentaikhoan
 * @property string $matkhau
 *
 * The followings are the available model relations:
 * @property FormDanhSachNhaThauThamGiaDauThau[] $formDanhSachNhaThauThamGiaDauThaus
 * @property FormKeHoachDauThau[] $formKeHoachDauThaus
 * @property FormKetQuaDauThau[] $formKetQuaDauThaus
 * @property FormThongBaoMoiThau[] $formThongBaoMoiThaus
 * @property FormThongTinKhac[] $formThongTinKhacs
 * @property TblLog[] $tblLogs
 */
class Admin extends CActiveRecord
{
    const ACCOUNT_LOCKED =0;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_admin';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('status', 'numerical', 'integerOnly'=>true),
			array('ho_va_ten, email, role, tentaikhoan, matkhau', 'length', 'max'=>50),
			array('so_dien_thoai, id_nguoi_tao, id_nguoi_chinh_sua', 'length', 'max'=>20),
			array('ngay_sinh, ngay_tao, ngay_chinh_sua', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, ho_va_ten, so_dien_thoai, email, status, ngay_sinh, ngay_tao, ngay_chinh_sua, id_nguoi_tao, id_nguoi_chinh_sua, role, tentaikhoan, matkhau', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'formDanhSachNhaThauThamGiaDauThaus' => array(self::HAS_MANY, 'FormDanhSachNhaThauThamGiaDauThau', 'id_nguoi_duyet'),
			'formKeHoachDauThaus' => array(self::HAS_MANY, 'FormKeHoachDauThau', 'id_nguoi_duyet'),
			'formKetQuaDauThaus' => array(self::HAS_MANY, 'FormKetQuaDauThau', 'id_nguoi_duyet'),
			'formThongBaoMoiThaus' => array(self::HAS_MANY, 'FormThongBaoMoiThau', 'id_nguoi_duyet'),
			'formThongTinKhacs' => array(self::HAS_MANY, 'FormThongTinKhac', 'id_nguoi_duyet'),
			'tblLogs' => array(self::HAS_MANY, 'TblLog', 'admin_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'ho_va_ten' => 'Ho Va Ten',
			'so_dien_thoai' => 'So Dien Thoai',
			'email' => 'Email',
			'status' => 'Status',
			'ngay_sinh' => 'Ngay Sinh',
			'ngay_tao' => 'Ngay Tao',
			'ngay_chinh_sua' => 'Ngay Chinh Sua',
			'id_nguoi_tao' => 'Id Nguoi Tao',
			'id_nguoi_chinh_sua' => 'Id Nguoi Chinh Sua',
			'role' => 'Role',
			'tentaikhoan' => 'Tentaikhoan',
			'matkhau' => 'Matkhau',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('ho_va_ten',$this->ho_va_ten,true);
		$criteria->compare('so_dien_thoai',$this->so_dien_thoai,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('ngay_sinh',$this->ngay_sinh,true);
		$criteria->compare('ngay_tao',$this->ngay_tao,true);
		$criteria->compare('ngay_chinh_sua',$this->ngay_chinh_sua,true);
		$criteria->compare('id_nguoi_tao',$this->id_nguoi_tao,true);
		$criteria->compare('id_nguoi_chinh_sua',$this->id_nguoi_chinh_sua,true);
		$criteria->compare('role',$this->role,true);
		$criteria->compare('tentaikhoan',$this->tentaikhoan,true);
		$criteria->compare('matkhau',$this->matkhau,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Admin the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
